package com.temp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.temp.dto.SearchTranRecordDTO;
import com.temp.entity.TransactionRecordView;
import com.temp.entity.Withdraw;
import com.temp.mapper.WithdrawMapper;
import com.temp.service.WithdrawService;
import com.temp.vo.CustomPageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

@Service
public class WithdrawServiceImpl extends ServiceImpl<WithdrawMapper, Withdraw> implements WithdrawService {

    @Autowired
    private WithdrawMapper withdrawMapper;

    @Override
    public CustomPageVO<TransactionRecordView> findAllTransactionRecords(SearchTranRecordDTO searchTranRecordDTO) {
        CustomPageVO<TransactionRecordView> customPageVO = new CustomPageVO<>();
        Integer count = Optional.ofNullable(withdrawMapper.countAllTransactionRecord(searchTranRecordDTO)).orElse(0);
        customPageVO.setTotal(count);
        if(count < 1) {
            customPageVO.setDataList(Collections.emptyList());
            return customPageVO;
        }

        List<TransactionRecordView> transactionRecords = withdrawMapper.findAllTransactionRecord(searchTranRecordDTO);
        customPageVO.setDataList(transactionRecords);
        return customPageVO;
    }
}
